// pages/exchangerecord/exchangerecord.js
const {
  config
} = require('../../utils/config.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sts:100
  },

  cancel(e){
    let that = this
    wx.showModal({
      cancelColor: 'cancelColor',
      title: '提示',
      content: '是否取消兑换？',
      success(res){
        if(res.confirm){
          wx.request({
            url: `${config}/erp/erpWeChat/erpwechatintegralrecord/cancelGood`,
            data: {
              exchangeId:e.currentTarget.dataset.changeid.exchange_id,
              integralTake:e.currentTarget.dataset.changeid.integralTake,
              stuId:app.globalData.userInfo.id,
            },
            success(res){
              that.getExchangeRecord()
              wx.showToast({
                title: '取消成功!',
              })
            }
          })
        }else{

        }
       
      }
    })
   
  },
  getExchangeRecord(){
    var that = this
    wx.request({
      url: `${config}/erp/erpWeChat/erpwechatintegralrecord/getExchangeRecord`,
      data: {
        stuId:app.globalData.userInfo.id,
        status:that.data.sts
      },
      success(res){
        console.log(res);
        if(res.data.exchangeRecord){
          that.setData({
            exchangeRecord: res.data.exchangeRecord
          })
          console.log(that.data.exchangeRecord);
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    if(options.status != undefined){
      that.setData({
        sts : options.status
      })
    }
    this.getExchangeRecord()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  onStsTap(e){
    this.setData({
      sts:e.currentTarget.dataset.sts
    })
    this.getExchangeRecord()
  }

  
})